
import fetchJson from './fetchJson'
import tools from './tools'
import Config from './config'
import eventBus from '../eventBus'
export default {
  start () {
<<<<<<< HEAD
    this.getFiberList()
  },

  getFiberList () {
    eventBus.bus.$emit('showLoading')
    fetchJson.getJson({
      self: this,
      url: '/cable/listasjson/',
=======
    this.getFiberList('start=0&limit=50')
    this.getSession()
    var _this = this
    _this.key = ''
    _this.value = ''
    eventBus.bus.$on('changePage', function (data) {
      if (data.page < 1) data.page = 1
      var startNum = (data.page - 1) * 50
      var d = 'start=' + startNum + '&limit=50'
      if (_this.key) {
        d = 'start=' + startNum + '&limit=50&' + _this.key + '=' + _this.value
      } 
       _this.getFiberList(d)     
    })

    eventBus.bus.$on('searchUserName', function (data) {
      // if (data.page < 1) data.page = 1
       var startNum = 0
       _this.key = data.key
       _this.value = data.value
       var d = 'start=' + startNum + '&limit=50&' + _this.key + '=' + _this.value
       console.log('this message list!')
       _this.getFiberList(d)     
    })
  },

  getFiberList (data) {
    eventBus.bus.$emit('showLoading')
    fetchJson.getJson({
      self: this,
      url: '/log/listsyslog/?' + data,
>>>>>>> 118bfb24f1cbdee8aba2f4af5269fcf3bfe2e597
      callback: this.callback,
      error: this.error
    })
  },

<<<<<<< HEAD
  callback (json) {
    eventBus.bus.$emit('hideLoading')
    if (json.code === 1) {
      eventBus.bus.$emit('getFiberList', json.items)
=======
  getSession () {
    eventBus.bus.$emit('showLoading')
    fetchJson.getJson({
      self: this,
      url: '/user/onlineusers/',
      callback: this.callbackSession,
      error: this.error
    })
  },

  callbackSession (json) {
     console.log('json:', json)
    eventBus.bus.$emit('hideLoading')
    if (json.code === 1) {
      console.log('getSessionListConfig hhhhhhhhhhhhhhh:', json, json.items)
      eventBus.bus.$emit('getSessionListConfig', json.data)
    } else {
      eventBus.bus.$message({
        message: json.message,
        type: 'warning'
      })
    }
  },

  callback (json) {
    eventBus.bus.$emit('hideLoading')
    if (json.code === 1) {
      eventBus.bus.$emit('getFiberList', json)
>>>>>>> 118bfb24f1cbdee8aba2f4af5269fcf3bfe2e597
    } else {
      eventBus.bus.$message({
        message: json.message,
        type: 'warning'
      })
    }
  },

  error () {
    eventBus.bus.$emit('hideLoading')
  }
  
}
